//
//  RootViewController.m
//  TagCloudDemo
//
//  Created by TravelRound on 15/9/28.
//  Copyright (c) 2015年 TravelRound. All rights reserved.
//

#import "RootViewController.h"
#import "DBSphereView.h"

@interface RootViewController ()

@property (nonatomic, retain) DBSphereView *sphereView;

@end

@implementation RootViewController

- (void)dealloc
{
    [_sphereView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    UIImageView *backIV = [[UIImageView alloc] initWithFrame:self.view.frame];
    backIV.userInteractionEnabled = YES;
    backIV.image = [UIImage imageNamed:@"brackground.jpg"];
    [self.view addSubview:backIV];
    [backIV release];
    
    
    NSArray *nameArr = [NSArray arrayWithObjects:
                        @"许博",
                        @"易志强",
                        @"初旭",
                        @"孙阳",
                        @"杜聿卓",
                        @"杨忠祥",
                        @"马广川",
                        @"朱洪旭",
                        @"赵伟",
                        @"刘庆春",
                        @"孙晓平",
                        @"魏冬冬",
                        @"邹雨",
                        @"谭博阳",
                        @"宋玉",
                        @"李千千",
                        @"葛河俊",
                        @"苗延宇",
                        @"郎学东",
                        @"孙巍山",
                        @"朱觐",
                        @"王博男",
                        @"王宁",
                        @"毕康善",
                        @"李双阳",
                        @"孙云璞",
                        @"孙明发",
                        @"郭鹏浩",
                        @"高帅",
                        @"夏宁宁",
                        @"薛东升",
                        @"王琼",
                        @"李金明",
                        @"由盛炎",
                        @"余浩",
                        nil];
    
    NSArray *arr = [NSArray arrayWithObjects:@"唱歌", @"笑话", @"同桌", @"后面", @"庆春儿", @"PASS", @"前面", @"指定", nil];
    
    self.sphereView = [[DBSphereView alloc] initWithFrame:CGRectMake(0, 150, self.view.frame.size.width, self.view.frame.size.height)];
    
    NSMutableArray *array = [NSMutableArray array];
    
    for (NSInteger i = 0; i < nameArr.count; i ++) {
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:[nameArr objectAtIndex:i] forState:UIControlStateNormal];
//                [btn setTitle:@"✨" forState:UIControlStateSelected];
        [btn setTitle:[arr objectAtIndex:arc4random() % arr.count] forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor colorWithRed:(arc4random() % 256) / 255.0 green:(arc4random() % 256) / 255.0 blue:(arc4random() % 256) / 255.0 alpha:1.0] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:24.];
        btn.frame = CGRectMake(0, 0, 75, 20);
        [btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [array addObject:btn];
        
        [self.sphereView addSubview:btn];
        
    }
    
    [self.sphereView setCloudTags:array];
    self.sphereView.backgroundColor = [UIColor clearColor];
    [backIV addSubview:self.sphereView];
    [_sphereView release];
    
}

- (void)buttonPressed:(UIButton *)btn
{
    
    btn.selected = !btn.selected;
    [self.sphereView timerStop];
    
    [UIView animateWithDuration:0.3 animations:^{
        
        btn.transform = CGAffineTransformMakeScale(2., 2.);
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.3 animations:^{
            btn.transform = CGAffineTransformMakeScale(1., 1.);
            
        } completion:^(BOOL finished) {
            
            [self.sphereView timerStart];
            
        }];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
